package youcaihuaoa.weetop.com.ui.main

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.core.widget.addTextChangedListener
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.configs.PrefsManager
import com.robot.base.model.CustomListItemBean
import com.robot.base.model.UserInfoBean
import com.robot.base.util.arouter.ARouterUtil
import youcaihuaoa.weetop.com.BR
import youcaihuaoa.weetop.com.R
import youcaihuaoa.weetop.com.databinding.AppActivityAddFriendBinding
import youcaihuaoa.weetop.com.databinding.AppActvityMyApplyBinding
import youcaihuaoa.weetop.com.ui.adapter.FriendAdapter
import youcaihuaoa.weetop.com.ui.adapter.MyApplyAdapter
import youcaihuaoa.weetop.com.vm.apply.MyApplyViewModel
import youcaihuaoa.weetop.com.vm.main.AddFriendViewModel

@Route(path = AppConstants.Router.Main.A_ADD_FRIEND)
class AddFriendActivity : GLBaseActivity<AppActivityAddFriendBinding, AddFriendViewModel>() {

    private lateinit var friendAdapter: FriendAdapter

    override fun initComponents() {
        addSingleTitleBar("通讯录")

        friendAdapter = FriendAdapter {
            val friend = friendAdapter.data[it]
            viewModel.addFriend(friend.id ?: "")
        }
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(this@AddFriendActivity)
            adapter = friendAdapter
        }

        binding.etSearch.addTextChangedListener {
            viewModel.fetchFriendList()
        }

        binding.tvUsername.text = "我的OA账号：${PrefsManager.getUserInfo().user_name}"
    }

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_add_friend

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewObservable() {
        viewModel.uiEvent.menuDataLiveEvent.observe(this) {
            friendAdapter.setNewInstance(it as MutableList<UserInfoBean>?)
        }
    }

    override fun initData() {

    }


}